﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;


public partial class PromeniNaracka : System.Web.UI.Page
{
    int list = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        string conString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        conn.Open();
        string select = "select ID from Poracki";
        OleDbCommand cmd = new OleDbCommand(select, conn);
        OleDbDataReader citaj = cmd.ExecuteReader();
        ListItem item = new ListItem();
        if (!IsPostBack)
        {
            while (citaj.Read())
            {
                DropDownList1.Items.Add(item.Value = citaj.GetValue(0).ToString());
                list++;
            }
        }
        conn.Close();


    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        string constring = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(constring);
        conn.Open();
        string update = "update Poracki set Kolicina=?, Tip_na_naracka=?, Cena=? where ID=?";
        OleDbCommand cmd = new OleDbCommand(update, conn);
        cmd.Parameters.AddWithValue("?", TextBox1.Text.ToString());
        cmd.Parameters.AddWithValue("?", TextBox2.Text.ToString());
        cmd.Parameters.AddWithValue("?", TextBox3.Text.ToString());
        cmd.Parameters.AddWithValue("?", DropDownList1.SelectedItem.Text.ToString());
        cmd.ExecuteNonQuery();
        conn.Close();
        Response.Redirect("Naracki.aspx");

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string constring = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
OleDbConnection conn = new OleDbConnection(constring);
conn.Open();
string select = "select Kolicina,Tip_na_naracka,Cena from Poracki where ID=?";
OleDbCommand cmd = new OleDbCommand(select, conn);
cmd.Parameters.AddWithValue("?", DropDownList1.SelectedItem.Text.ToString());
OleDbDataReader rid = cmd.ExecuteReader();

rid.Read();
TextBox1.Text = rid.GetValue(0).ToString();
TextBox2.Text = rid.GetValue(1).ToString();
TextBox3.Text = rid.GetValue(2).ToString();
conn.Close();
}
}
    
